package com.zm.test;

import com.zm.dao.IUserDao;
import com.zm.domain.Usermy;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class SecondLevelCache {
    private InputStream in;
    private SqlSessionFactory sqlSessionFactory;

    @Before//测试方法之前执行
    public void init() throws IOException {
        in=Resources.getResourceAsStream("SqlMapConfig.xml");
        sqlSessionFactory= new SqlSessionFactoryBuilder().build(in);
    }
    @Test
    public  void testSecond(){
        SqlSession sqlSession=sqlSessionFactory.openSession();
        IUserDao userDao=sqlSession.getMapper(IUserDao.class);
        List<Usermy> usermyList=userDao.selectAll();
        System.out.println(usermyList);
        sqlSession.close();


        SqlSession sqlSession1=sqlSessionFactory.openSession();
        IUserDao  userDao2=sqlSession1.getMapper(IUserDao.class);
        List<Usermy> usermyList1=userDao2.selectAll();
        System.out.println(usermyList1);
        System.out.println(usermyList==usermyList1);
        sqlSession1.close();

    }

}
